extensions/CIE: do cbrt computation in single precision float
authorØyvind Kolås <pippin@gimp.org>
Fri, 13 Jan 2017 02:45:35 +0000 (03:45 +0100)
committerØyvind Kolås <pippin@gimp.org>
Fri, 13 Jan 2017 03:00:51 +0000 (04:00 +0100)
This is sufficient for our purposes, and gives a ~40% boost for
the affecte CIE Lab float conversions.

extensions/CIE.c

index fa9df1153ee5a1bb70ead2a6dddfe7db9a4fc777..e1e2fa747ce3e68ea48167ae964fdc70f5d5a3ae 100644 (file)
@@ -472,7 +472,7 @@ B2 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
 
 static inline float _cbrtf(float x)
 {
-       double_t r,T;
+       float r,T;
        union {float f; uint32_t i;} u = {x};
        uint32_t hx = u.i & 0x7fffffff;
 
@@ -491,23 +491,13 @@ static inline float _cbrtf(float x)
        u.i &= 0x80000000;
        u.i |= hx;
 
-       /*
-        * First step Newton iteration (solving t*t-x/t == 0) to 16 bits.  In
-        * double precision so that its terms can be arranged for efficiency
-        * without causing overflow or underflow.
-        */
        T = u.f;
        r = T*T*T;
-       T = T*((double_t)x+x+r)/(x+r+r);
+       T = T*((float)x+x+r)/(x+r+r);
 
-       /*
-        * Second step Newton iteration to 47 bits.  In double precision for
-        * efficiency and accuracy.
-        */
        r = T*T*T;
-       T = T*((double_t)x+x+r)/(x+r+r);
+       T = T*((float)x+x+r)/(x+r+r);
 
-       /* rounding to 24 bits is perfect in round-to-nearest mode */
        return T;
 }